<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: product_models.php 566 2015-02-28 12:39:20Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 566 $
* 	zuletzt geaendert von:	$Author: $
* 	Datum:					$Date: 2015-02-28 12:39:20 +0000 (Sat, 28 Feb 2015) $
*
* 	extends by dirk.mueller (edv-mueller.com)
* 	http://www.itdotmedia.de
*
* --------------------------------------------------------------------------------------
* 	based on:
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
* 	Copyright (c) since 2011 SEO:mercari
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

if (!defined('TABLE_PRODUCTS_TO_MODELS'))
  define('TABLE_PRODUCTS_TO_MODELS', DB_PREFIX.'products_to_models');

$module_smarty = new Smarty;
$module_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');
$module_smarty->assign('language', $_SESSION['language']);

if($_SESSION['customers_status']['customers_fsk18_display'] == '0')
	$fsk_lock = ' AND p.products_fsk18 != 1';

if(GROUP_CHECK == 'true')
	$group_check = " AND p.group_permission_".$_SESSION['customers_status']['customers_status_id']." = 1 ";

//$products_models_ = $db->db_query_limit("

$sql = "
  select
    p.products_id,
  	pd.products_name, p.products_image,
  	p.products_price, p.products_tax_class_id,
  	p.products_shippingtime,
  	pd.products_description
  from
  	".TABLE_PRODUCTS_TO_MODELS." m
  	inner join mercari_products p
  		on m.products_model = p.products_id and p.products_status = 2
  	inner join mercari_products_description pd
  		on pd.products_id = p.products_id and pd.language_id = '".(int) $_SESSION['languages_id']."'
  where
  	m.products_id = '".$product->data['products_id']."'
  	".$fsk_lock.$group_check."
  order by
    p.products_price";
$products_model_query = $db->db_query($sql, true);

if($products_model_query->_numOfRows > 0) {
	$products_models = array();
	while(!$products_model_query->EOF) {
		$products_models[] = array(
      'id' => $products_model_query->fields['products_id'],
      'name' => $products_model_query->fields['products_name'],
      'description' => $products_model_query->fields['products_description'],
      'price' => $price->GetPrice($products_model_query->fields['products_id'], true, 1, $products_model_query->fields['products_tax_class_id'], $products_model_query->fields['products_price']),
      'image' => (!empty($products_model_query->fields['products_image']) ? DIR_WS_THUMBNAIL_IMAGES.$products_model_query->fields['products_image'] : ''),
      'link' => href_link(FILENAME_PRODUCT_INFO, 'products_id='.$products_model_query->fields['products_id']),
      'special' => $price->CheckSpecial($products_model_query->fields['products_id'])
    );

		if(ACTIVATE_SHIPPING_STATUS == 'true' && DELIVERY_SHOW == 'true') {
			$products_models[count($products_models)-1]['SHIPPING_NAME'] 
				= $main->getShippingStatusName($products_model_query->fields['products_shippingtime']);
		}

		$products_model_query->MoveNext();
	}
}

$module_smarty->assign('PRODUCT_RELATED_CAT', $products_models);
$module_smarty->assign('PRODUCTS_COUNT', count($products_models));
$info_smarty->assign('PRODUCT_RELATED_CAT_COUNT', count($products_models));

if (!CacheCheck()) {
	$module_smarty->caching = false;
	$module_products_models = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/product_related_products_carusel.html');
} else {
	$module_smarty->caching = true;
	$module_smarty->cache_lifetime = CACHE_LIFETIME;
	$module_smarty->cache_modified_check = CACHE_CHECK;
	$cache_id = __FILE__.'_'.$product->data['products_id'].$_SESSION['language'].$_SESSION['customers_status']['customers_status_name'].$_SESSION['currency'];
	$module_products_models = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/product_related_products_carusel.html', $cache_id);
}
$info_smarty->assign('MODULE_product_models', $module_products_models);
?>